<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎注册</title>
    <link href="../css/register.css" rel="stylesheet">
</head>
<body>

<div class="form-div">
    <div class="reg-content">
        <h1>欢迎注册</h1>
        <span>已有帐号？</span> <a href="#">登录</a>
    </div>
    <form id="reg-form" action="#" method="get">

        <table>
            <tr>
                <td>用户名</td>
                <td class="inputs">
                    <input name="username" type="text" id="username">
                    <br>
                    <span id="username_err1" class="err_msg" style="display: none">用户名长度不能小于6</span>
                    <span id="username_err2" class="err_msg" style="display: none">用户名长度不能大于12</span>
                </td>

            </tr>

            <tr>
                <td>密码</td>
                <td class="inputs">
                    <input name="password" type="password" id="password">
                    <br>
                    <span id="password_err" class="err_msg" style="display: none">密码格式有误</span>
                </td>
            </tr>


            <tr>
                <td>手机号</td>
                <td class="inputs"><input name="tel" type="text" id="tel">
                    <br>
                    <span id="tel_err" class="err_msg" style="display: none">手机号格式有误</span>
                </td>
            </tr>

        </table>

        <div class="buttons">
            <input value="注 册" type="submit" id="reg_btn">
        </div>
        <br class="clear">
    </form>

</div>


<script>
var use = document.getElementById("username");
use.onblur = function () {
    var a = use.value;
    let  flag = a.length >= 6 && a.length <= 12;
    if(a.length >= 6){
        document.getElementById("username_err1").style.display= "none";
        document.getElementById("username_err2").style.display= "";
    }else if(a.length <= 12){
        document.getElementById("username_err1").style.display = "";
        document.getElementById("username_err2").style.display = "none";
    }else {
        document.getElementById("username_err1").style.display = "";
        document.getElementById("username_err2").style.display = "";
    }
}
var name = document.getElementById("password");
name.onblur = function () {
    var value = name.value;
    let  flag = value.length >= 6 && value.length <= 12;
    if(flag){
        document.getElementById("password_err").style.display= "none";
    }else {
        document.getElementById("password_err").style.display = "";
    }
}
var name = document.getElementById("tel");
name.onblur = function () {
    var value = name.value;
    let  flag = value.length ==11 ;
    if(flag){
        document.getElementById("tel_err").style.display= "none";
    }else {
        document.getElementById("tel_err").style.display = "";
    }
}

</script>
</body>
</html>